package cn.com.gzheroli.core.util;

import com.google.common.collect.Lists;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dozer.DozerBeanMapper;
import org.dozer.DozerBeanMapperSingletonWrapper;
import org.dozer.Mapper;
import org.dozer.converters.DateConverter;

/**
* 类描述： bean map 转换类
* @version 1.0 CreateDate: 2015-2-10
*
* @history：
* @updateDate	@updatePerson	@declare
* 
*/
public class BeanMapper {
	private static Mapper dozer = new DozerBeanMapper();
	//private static Mapper  dozer =DozerBeanMapperSingletonWrapper.getInstance();
	//private static DateConverter converter = new DateConverter(DataUtils.yyyymmddhhmmss);
	/**
	* 方法描述：map 转 bean
	* @param <T>
	* @param map
	* @param destinationClass
	* @return
	*/
	public static <T> T mapToBean(Map<String,?> map, Class<T> destinationClass) {
		return dozer.map(map, destinationClass);
	}

	/**
	* 方法描述：bean 转map
	* @param source
	* @return
	*/
	public static Map<String,Object> beanToMap(Object source) {
		HashMap<String,Object> map = new HashMap<String,Object>();
		dozer.map(source, map);
		return map;
	}
	
	 public static <T> List<T> mapList(List<Map<String,Object>> sourceList, Class<T> destinationClass)  
	  {  
	    List destinationList = Lists.newArrayList();  
	    for(Map<String,Object> map:sourceList){
	    	Object destinationObject = MyBeanUtils.copyMap2Bean_Dozer(destinationClass,map);  
	    	//Object destinationObject = dozer.map(map, destinationClass);  
	    	destinationList.add(destinationObject);  
	    }  
	    return destinationList;  
	  } 
	 /** 
	  * 将对象source的所有属性值拷贝到对象destination中. 
	  *  
	  * @param source 对象source 
	  * @param destination 对象destination 
	  */  
	  public static void copy(Object source, Object destinationObject)  
	  {  
	    dozer.map(source, destinationObject);  
	  }
}
